﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cspl.Calculator.Library.Interface;

namespace Cspl.Calculator.Library
{
    public class BasicCalculator : IBasicCalculator
    {
        public int Add(int a, int b)
        {
            return a + b;
        }

        public int Sub(int a, int b)
        {
            return a - b;
        }

        public int Mul(int a, int b)
        {
            return a * b;
        }

        public int Div(int a, int b)
        {
            int retval;
            try
            {
                retval = a / b;
            }
            catch (Exception ex)
            {
                retval = 0;
                Console.WriteLine("An execption occurred : " + ex.Message);
            }
            return retval;
        }

        public int ComplexListOperation(IEnumerable<int> listOfNumber, CalOperations calOp)
        {
            int retval = 0;
            foreach (int number in listOfNumber)
            {
                switch (calOp)
                {
                    case CalOperations.Add:
                        retval += number;
                        break;
                    case CalOperations.Mul:
                        retval *= number;
                        break;
                    case CalOperations.Div:
                        retval /= number;
                        break;
                    case CalOperations.Sub:
                        retval -= number;
                        break;
                    default:
                        break;
                }
            }
            return retval;
        }

        //public int AddList(IEnumerable<int> listOfNumber)
        //{
        //    int retval = 0;
        //    foreach (int number in listOfNumber)
        //    {
        //        retval += number;
        //    }
        //    return retval;
        //}



        
    }
}
